# API

## GenFarmer API Documentation

Welcome to the GenFarmer API documentation. This guide helps you understand how to interact with the GenFarmer automation system via RESTful APIs.

***

### 🧠 Overview

GenFarmer provides endpoints to manage **Automation Apps**, **Tasks**, and **Runs** that can be assigned to devices for automation scenarios.

***

### 📦 Base URL

```
http://127.0.0.1:55554/
```

***

### 📁 Automation APIs

#### 🔍 List Apps

* **Method:** `GET`
* **Endpoint:** `/automation/apps`

**cURL Example:**

```bash
curl -X GET 'http://127.0.0.1:55554/automation/apps?userId=3&page=1&limit=25&order=desc&orderBy=updatedAt'
```

🔍 Get App Details

* **Method:** `GET`
* **Endpoint:** `/automation/apps/:id`

**cURL Example:**

```bash
curl -X GET 'http://127.0.0.1:55554/automation/apps/adoFNVNN6Jwl8FlbZCfni'
```

#### 🔧 Update App

* **Method:** `PUT`
* **Endpoint:** `/automation/apps`

**cURL Example:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/apps' \
  -H 'Content-Type: application/json' \
  -d '{"id":"adoFNVNN6Jwl8FlbZCfni","userId":3,"name":"New App","description":"","version":"1.0.0","script":{"flow":{"nodes":[],"edges":[]}}}'
```

#### ❌ Delete App

* **Method:** `DELETE`
* **Endpoint:** `/automation/apps`

**cURL Example:**

```bash
curl -X DELETE 'http://127.0.0.1:55554/automation/apps' \
  -H 'Content-Type: application/json' \
  -d '{"ids": ["2ykTiCbEOAYC_5_tR5Wp-"]}'
```

***

### 🧾 Task APIs

#### ➕ Create Task

* **Method:** `POST`
* **Endpoint:** `/automation/tasks`

**cURL Example:**

```bash
curl -X POST 'http://127.0.0.1:55554/automation/tasks' \
  -H 'Content-Type: application/json' \
  -d '{"appId":"adoFNVNN6Jwl8FlbZCfni","input":[],"userId":3,"name":"test","devices":{"enable":true,"list":[]}}'
```

#### 📄 List Tasks

* **Method:** `GET`
* **Endpoint:** `/automation/runs`

**cURL Example:**

```bash
curl -X GET 'http://127.0.0.1:55554/automation/runs?userId=3&page=1&limit=25&order=desc&orderBy=createdAt'
```

#### 🛠 Update Task

* **Method:** `PUT`
* **Endpoint:** `/automation/tasks/:id`

**cURL Example:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/tasks/uNDVKT_VwhEDuXT3PGUUv' \
  -H 'Content-Type: application/json' \
  -d '{"id":"uNDVKT_VwhEDuXT3PGUUv","userId":3,"appId":"adoFNVNN6Jwl8FlbZCfni","taskSource":0,"name":"test","input":[],"enableInput":true,"devices":{"enable":true,"list":[{"id":"emulator-5554","serialNo":"00f65a5d","name":"SM-G960N"}]}}'
```

#### 🔗 Assign Devices to Task

* **Method:** `PUT`
* **Endpoint:** `/automation/tasks/:id/add-devices`

**cURL Example:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/tasks/uNDVKT_VwhEDuXT3PGUUv/add-devices' \
  -H 'Content-Type: application/json' \
  -d '{"devices":{"enabled":true,"list":[{"id":"emulator-5554","serialNo":"00f65a5d","name":"SM-G960N"}]}}'
```

#### 🔗 Remove Devices from Task

* **Method:** `PUT`
* **Endpoint:** `/automation/tasks/:id/remove-devices`

#### 🗑 Delete Task

* **Method:** `DELETE`
* **Endpoint:** `/automation/tasks`

**cURL Example:**

```bash
curl -X DELETE 'http://127.0.0.1:55554/automation/tasks' \
  -H 'Content-Type: application/json' \
  -d '{"ids": ["uNDVKT_VwhEDuXT3PGUUv"]}'
```

***

### 🚀 Run APIs

#### ▶️ Create Run

* **Method:** `POST`
* **Endpoint:** `/automation/runs`

**cURL Example:**

```bash
curl -X POST 'http://127.0.0.1:55554/automation/runs' \
  -H 'Content-Type: application/json' \
  -d '{"userId":3,"taskId":"uNDVKT_VwhEDuXT3PGUUv","appId":"adoFNVNN6Jwl8FlbZCfni","status":0}'
```

#### ▶️ Execute Run

* **Method:** `PUT`
* **Endpoint:** `/automation/runs/:id/run`

**cURL Example:**

```bash
curl -X PUT 'http://127.0.0.1:55554/automation/runs/xhfjAeUOB5SXC8d5RiK_c/run' \
  -H 'Content-Type: application/json' \
  -d '{"deviceIds":[]}'
```

#### 📊 Get Run Output

* **Method:** `GET`
* **Endpoint:** `/automation/runs/:id/storages`

**cURL Example:**

```bash
curl -X GET 'http://127.0.0.1:55554/automation/runs/xhfjAeUOB5SXC8d5RiK_c/storages?page=1&limit=25'
```

***

### 👤 Me API

#### 🙋‍♂️ Get Current User

* **Method:** `GET`
* **Endpoint:** `/backend/auth/me`

**cURL Example:**

```bash
curl -X GET 'http://127.0.0.1:55554/backend/auth/me'
```

***

### 📘 Notes

* Replace all `:id` placeholders with the actual `id` of your app, task, or run.
* The `script.flow` field in Update App allows defining an automation logic visually using nodes and edges.

***

### 📥 Download Postman Collection

{% file src="<https://605836273-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F7JJxETkZAGywbrUL9WJl%2Fuploads%2FBJGpzhqJPTIFaWBfuZpj%2FGenFarmer.postman_collection.json?alt=media&token=6d7b2761-005e-4b8e-8d3b-5ee1d8614792>" %}

### 📞 Support

For further help, please contact the GenFarmer support team.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://genfarmer-support.gitbook.io/genfarmer-eng/main-menu-bar/api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
